package com.example.hotel;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.StrictMode;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class About extends Activity implements OnClickListener {
	TextView about, wellcome;
	String image = "";
	String aboutTxt = "";
	Bitmap imag = null;
	ImageView about_image, imageback, back_home, image_cart, image_msg,
			image_bill;
	URL url = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.about);
		if (android.os.Build.VERSION.SDK_INT > 9) {
			StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
					.permitAll().build();
			StrictMode.setThreadPolicy(policy);
		}
		about_image = (ImageView) findViewById(R.id.about_image);
		imageback = (ImageView) findViewById(R.id.imageback);
		back_home = (ImageView) findViewById(R.id.imagehome);
		image_cart = (ImageView) findViewById(R.id.image_cart);
		image_msg = (ImageView) findViewById(R.id.image_msg);
		image_bill = (ImageView) findViewById(R.id.image_bill);
		back_home.setOnClickListener(this);
		imageback.setOnClickListener(this);
		image_msg.setOnClickListener(this);
		image_cart.setOnClickListener(this);
		image_bill.setOnClickListener(this);
		about = (TextView) findViewById(R.id.info);
		wellcome = (TextView) findViewById(R.id.tvWellcome);
		wellcome.setText(((Global) getApplicationContext()).wellcome);
		TextView tvAmount = (TextView) findViewById(R.id.tvAmount);
		tvAmount.setText("("
				+ ((Global) getApplicationContext()).cart_count.toString()
				+ ")");
		getAbout();

		try {

			url = new URL(image);

		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		try {
			imag = BitmapFactory.decodeStream(url.openStream());

		} catch (IOException e) {
			e.printStackTrace();
		}

		about_image.setImageBitmap(imag);
		about.setText(Html.fromHtml(aboutTxt));

		/*------setfonts------*/
		Typeface Font = Typeface.createFromAsset(getAssets(),
				"fonts/PSL-Kittithada.ttf");
		Typeface FontBold = Typeface.createFromAsset(getAssets(),
				"fonts/PSL-KittithadaBold.ttf");
		TextView tv_amount = (TextView) findViewById(R.id.tvAmount);

		tv_amount.setTypeface(Font);
		about.setTypeface(Font);
		wellcome.setTypeface(FontBold);
		/*--------------------*/
		((Global) getApplicationContext()).callpage1 = com.example.hotel.Hotel_info.class;
	}

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.imagehome:
			startActivity(new Intent(About.this, home.class));
			break;
		case R.id.imageback:
			Class myClass = ((Global) getApplicationContext()).callpage1;
			Intent intent = new Intent(About.this, myClass);
			startActivity(intent);
			break;
		case R.id.image_cart:
			((Global) getApplicationContext()).callpage1 = com.example.hotel.About.class;
			((Global) getApplicationContext()).nameCart = "show_cart";
			startActivity(new Intent(About.this, Add_cart.class));
			break;
		case R.id.image_msg:
			((Global) getApplicationContext()).callpage1 = com.example.hotel.About.class;
			startActivity(new Intent(About.this, Message_list.class));
			break;
		case R.id.image_bill:
			((Global) getApplicationContext()).callpage1 = com.example.hotel.About.class;
			startActivity(new Intent(About.this, Billing_history.class));
			break;
		}
	}
	public void getAbout() {
		String URL1 = ((Global) getApplicationContext()).url;
		String SOAP_ACTION = ((Global) getApplicationContext()).soap_acction
				+ "about";
		String NAMESPACE = "";
		String METHOD_NAME = "about";
		String imei = ((Global) getApplicationContext()).imei;
		String lang = ((Global) getApplicationContext()).lang;
		// String imei = "1";
		String str = "";
		SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
		SoapObject responses = null;
		request.addProperty("id", imei);
		request.addProperty("lang", lang);
		// request.addProperty("room","0001");
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;
		envelope.setOutputSoapObject(request);
		HttpTransportSE androidHttpTransport = new HttpTransportSE(URL1);
		androidHttpTransport.debug = true;

		try {
			androidHttpTransport.call(SOAP_ACTION, envelope);
			responses = (SoapObject) envelope.bodyIn;

			str = responses.toString();

			int indexSub = str.indexOf("=");

			String b = str.substring(indexSub + 1);
			String[] a = b.split("\\|");
			indexSub = a[1].indexOf(";");
			a[1] = a[1].substring(0, indexSub);
			aboutTxt = a[0];
			image = a[1];
		} catch (Exception e) {
			Toast.makeText(getApplicationContext(), "Not connect internet",
					Toast.LENGTH_LONG).show();

		}

	}

}
